package com.hucc.redislock.command;

import com.hucc.redislock.RedisCommand;
import com.hucc.redislock.RedisLockContext;
import com.hucc.redislock.result.CommandResult;
import redis.clients.jedis.Jedis;

import java.util.List;

public abstract class AbstractRedisCommand<T> implements RedisCommand<T> {
    protected String lockName;

    protected String threadName;

    public AbstractRedisCommand() {
    }

    public AbstractRedisCommand(String lockName, String threadName) {
        this.lockName = lockName;
        this.threadName = threadName;
    }

    protected String getChannelName(String name) {
        return "redis_lock_channel:" + name;
    }

    protected Object executeScript(String script, List<String> keys, List<String> args) {
        Jedis jedis = RedisLockContext.getJedis();
        Object evalResult = jedis.eval(script, keys, args);
        jedis.close();
        return evalResult;
    }
}
